package com.xy.wsl.api.controller.Util;

import com.xy.wsl.api.request.EncodeRequest;
import com.xy.wsl.api.response.ResponseResult;
import com.xy.wsl.api.utils.SecretUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;

@RequestMapping("/util")
@Slf4j
@RestController
@ResponseResult
public class UtilController {


    private String key = "WangshenglongXYI";


    @PostMapping("/encode/aes")
    public String encodeAES(@RequestBody EncodeRequest request) {

        try {
            return SecretUtil.encrypt_aes(request.getMessage(),key);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @PostMapping("decode/aes")
    public String decodeAES(@RequestBody EncodeRequest request) {
        try {
            return SecretUtil.decrypt_aes(request.getMessage(),key);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }



}
